package com.example.back.service.impl;

import com.example.back.model.Post;
import com.example.back.service.PostService;
import com.example.back.mapper.PostMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author jialily
 * @description 针对表【t_post】的数据库操作Service实现
 * @createDate 2022-05-05 12:20:50
 */
@Service("postService")
//支持事务，增加，删除，更新操作单独使用 propagation = Propagation.SUPPORTS
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public class PostServiceImpl implements PostService {

    @Autowired
    PostMapper postMapper;

    @Override
    public List<Post> selectAll() {
        return this.postMapper.selectAll();
    }

    @Override
    public Post selectDetail(String itemId) {
        return this.postMapper.selectDetail(itemId);
    }

    @Override
    public int updatePost(int id, String name, String information) {
        return this.postMapper.updatePost(id,name,information);
    }

    @Override
    public int deletePost(int id) {
        return this.postMapper.deletePost(id);
    }

    @Override
    public int insertPost(String name, String information) {
        return this.postMapper.insertPost(name,information);
    }
}
